package com.sumainfor.pc.market.service.tenant.impl;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.dao.tenant.KeepMapper;
import com.sumainfor.pc.market.feign.GmioFeign.GmioFeign;
import com.sumainfor.pc.market.feign.ZuulFeign.ZuulFeign;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述:
 * 租客端管家相关
 * @Auther: zhlu
 * @Date: 2019/4/6 18:14
 * @Description:
 */
@Service
public class KeepService {

    @Autowired
    KeepMapper KeepMapper;

    @Autowired
    ZuulFeign ZuulFeign;

    @Autowired
    GmioFeign GmioFeign;

    /**
     * 功能描述: 
     * 根据租客编号获取租客合同，然后找房源管家
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/6 18:38
     */
    public JsonResult getTenantKepp(Map<String,Object>params){
        JsonResult result=new JsonResult();
        Map<String,Object> getTenantKepp=KeepMapper.getTenantKepp(params);
        if(MapUtils.isNotEmpty(getTenantKepp)){
            JsonResult jsonResult=ZuulFeign.getUserMap(new HashMap<String,Object>(){{
                put("UserId",getTenantKepp.get("SysUserId"));
            }});
            if(jsonResult.isSuccess()==false){
                return jsonResult;
            }
            Map<String,Object>getUserMap=(Map<String,Object>)jsonResult.getResult();
            Map<String,Object> getKeepAvgRangeMap=(Map<String,Object>)GmioFeign.getKeepAvgRangeMap(new HashMap<String,Object>(){{
                put("SysUserId",getTenantKepp.get("SysUserId"));
            }}).getResult();
            getUserMap.putAll(getKeepAvgRangeMap);
            return result.put(getUserMap);
        }
        result.putFailed("当前租客未入住！");
        return result;
    }

}
